set -e

source ./make_openssl_3.0.7.sh

$openssl genpkey -genparam -algorithm DH -out dhp.pem
cat dhp.pem
$openssl pkeyparam -in dhp.pem -text

for i in {1..10000}
do
    $openssl genpkey -paramfile dhp.pem -out dhkey.pem
    $openssl pkey -in dhkey.pem -text -noout -out keypair.txt
    TrimOpensslText keypair.txt
    public_key=$(GetNthLine keypair.txt 5)
    echo $public_key
    public_key_text_len=$(echo -n $public_key | wc -c)
    public_key_byte_len=$(($public_key_text_len / 2))
    echo "public_key_byte_len = $public_key_byte_len"
    if [ $public_key_byte_len -lt 256 ]
    then
        echo "!!!!found!!!! iteration times: " $i
        break
    fi
done

$openssl pkey -inform pem -in dhkey.pem -pubout -out dhpubkey.pem
$openssl pkey -pubin -in dhpubkey.pem -outform DER -out dhpubkey.der
FileHexDump dhpubkey.der
